package com.dadi.broadcasttwo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.graphics.Color;
import android.media.AudioAttributes;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {
    final String TAG = "MainActivity";
    public static String id = "test_channel_01";
    MainFragment mFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String info = "Nothing";
        Bundle extras = getIntent().getExtras();
        if(extras != null){
            info = extras.getString("mText");
        }
        Log.wtf(TAG, "info is " + info);
        mFragment = MainFragment.newInstance(info);
        if(savedInstanceState == null){
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, mFragment).commit();

        } else {
            getSupportFragmentManager().beginTransaction()
                    .replace(R.id.container, mFragment).commit();
        }
//        createChannel();
    }

    /**
     *  for API 26+ create notification channels
     */
    private void createChannel() {
        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
            NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            NotificationChannel mChannel = new NotificationChannel(
                    id, getString(R.string.channel_name),
                    NotificationManager.IMPORTANCE_DEFAULT
            );
            mChannel.setDescription(getString(R.string.channel_name));
            mChannel.enableLights(true);
            mChannel.setLightColor(Color.RED);
            mChannel.enableVibration(true);
            mChannel.setShowBadge(true);
            mChannel.setVibrationPattern(new long[]{100, 200,300,400,500,400,300,200,400});
            nm.createNotificationChannel(mChannel);
        }
    }
}
